package com.iflytek.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iflytek.bean.Admin;
import com.iflytek.bean.Goods;
import com.iflytek.bean.StockInOrder;
import com.iflytek.mapper.GoodsMapper;
import com.iflytek.mapper.SioApproveMapper;
import com.iflytek.mapper.StockInOrderMapper;
import com.iflytek.service.SioApproveService;
import com.iflytek.vo.StockInOrderVO;

@Service
public class SioApproveServiceImpl implements SioApproveService{
	@Autowired
	private SioApproveMapper approveMapper;
	@Autowired
	private GoodsMapper goodMapper;
	@Autowired
	private StockInOrderMapper stockInOrderMapper;

	@Override
	public List<StockInOrderVO> selectByExample() {
		// TODO Auto-generated method stub
		return approveMapper.selectByExample();
	}

	@Override
	public void updateApproveStatus(Integer id) {
		approveMapper.updateApproveStatus(id);
	}

	@Override
	public List<StockInOrderVO> selectByStatus1() {
		return approveMapper.selectByStatus1();
	}
	
	public void updateGoodsNum(StockInOrder stockInOrder) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		stockInOrder.setApprover(admin.getName());
		System.out.println(stockInOrder.getApprover()+"=-============================");
		stockInOrderMapper.updateByPrimaryKeySelective(stockInOrder);
		Goods good = goodMapper.selectByPrimaryKey(stockInOrder.getGoodsId());
		if(stockInOrder.getGoodsNum()>0&&stockInOrder.getGoodsNum()<10000) {
			good.setGoodsNum(good.getGoodsNum()+ stockInOrder.getGoodsNum());
			goodMapper.updateByPrimaryKeySelective(good);
		}else {
			System.out.println("error of num");
		}
		
	}


	@Override
	public StockInOrderVO selectOrderById(Integer id) {
		return approveMapper.selectOrderById(id);
	}

}
